package cn.agiledata.bank.linkbank.impl.cmb;

import org.dom4j.Document;
import org.dom4j.Element;

import cn.agiledata.bank.common.util.XmlUtil;
import cn.agiledata.bank.linkbank.exception.LinkBankException;
import cn.agiledata.bank.linkbank.impl.AbstractBankTelPayRequestFeekback;

public class CmbTelPayRequestFeekback extends AbstractBankTelPayRequestFeekback {
    private String success;

    protected AbstractBankTelPayRequestFeekback getCopiedInstance() {
        CmbTelPayRequestFeekback requestFeekback = new CmbTelPayRequestFeekback();
        requestFeekback.success = this.success;
        return requestFeekback;
    }

    protected String getSuccessReturnCode() {
        return null;
    }

    public boolean isSuccessful() {
        return CmbTelConstant.SUCCESS_YES.equals(this.success);
    }

    public void setFeekback(String feekback) throws LinkBankException {
        try {
            Document doc = XmlUtil.createDocument(feekback);
            Element root = doc.getRootElement();
            this.success = root.elementTextTrim(CmbTelConstant.SUCCESS);
            setReturnCode(root.elementTextTrim(CmbTelConstant.ERROR_CODE));
            setReturnMessage(root.elementTextTrim(CmbTelConstant.ERROR_MESSAGE));
        } catch (Exception e) {
            throw LinkBankException.PARSE_RESPONSE_ERROR;
        }
    }

}
